% tkz-obj-eu-draw-lines.tex
% Copyright 2020  Alain Matthes
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status “maintained”.
%
% The Current Maintainer of this work is Alain Matthes.

%  utf8 encoding
\def\fileversion{3.06c}
\def\filedate{2020/04/06}
\typeout{2020/04/06 3.06c tkz-obj-eu-draw-lines.tex}
\makeatletter
\def\tkz@numdl{0}
\pgfkeys{/tkzdrawl/.cd,
      median/.code                  =   \def\tkz@numdl{0},
      altitude/.code                =   \def\tkz@numdl{1},
      bisector/.code                =   \def\tkz@numdl{2},
      none/.code                    =   \def\tkz@numdl{3},
      none,
   /tkzdrawl/.search also={/tikz}
}
%<--------------------------------------------------------------------------–>
%            Drawing a line                                                  >
%<--------------------------------------------------------------------------–>
\def\tkzDrawLine{\pgfutil@ifnextchar[{\tkz@DrawLine}{\tkz@DrawLine[]}}
\def\tkz@DrawLine[#1](#2){%
\begingroup
\pgfqkeys{/tkzdrawl}{#1}
\ifcase\tkz@numdl%
    \tkzDrawMedian[#1](#2)
  \or% 1
    \tkzDrawAltitude[#1](#2)
  \or% 2
    \tkzDrawBisector[#1](#2)
 \or% 3
   \tkzDrawSLine[#1](#2)
 \fi
\endgroup
}
%<--------------------------------------------------------------------------–>
%                       Droites particulières d'un triangle
%<--------------------------------------------------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDrawSLine{\pgfutil@ifnextchar[{\tkz@DrawSLine}{\tkz@DrawSLine[]}}
\def\tkz@DrawSLine[#1](#2,#3){%
\begingroup
\draw[line style,#1] (#2) to (#3);
\endgroup
}%
%<--------------------------------------------------------------------------–>
%                        median
%<--------------------------------------------------------------------------–>
\def\tkzDrawMedian{\pgfutil@ifnextchar[{\tkz@Median}{\tkz@Median[]}}
\def\tkz@Median[#1](#2,#3,#4){%
\begingroup
   \tkzDefMidPoint(#2,#4)
   \tkzDrawSLine[add= 0 and 0,/tkzdrawl/.cd,#1](#3,tkzPointResult)
\endgroup
}
%<--------------------------------------------------------------------------–>
%                         altitude
%<--------------------------------------------------------------------------–>
\def\tkzDrawAltitude{\pgfutil@ifnextchar[{\tkz@Altitude}{\tkz@Altitude[]}}
\def\tkz@Altitude[#1](#2,#3,#4){%
\begingroup
    \tkzUProjection(#2,#4)(#3)
    \tkzDrawSLine[add= 0 and 0,/tkzdrawl/.cd,#1](#3,tkzPointResult)
\endgroup
}
%<--------------------------------------------------------------------------–>
%                          bisector
%<--------------------------------------------------------------------------–>
\def\tkzDrawBisector{\pgfutil@ifnextchar[{\tkz@Bisector}{\tkz@Bisector[]}}
\def\tkz@Bisector[#1](#2,#3,#4){%
\begingroup
    \tkzDefBisectorLine(#2,#3,#4)
    \tkzInterLL(#2,#4)(#3,tkzPointResult)
    \tkzDrawSLine[add= 0 and 0,/tkzdrawl/.cd,#1](#3,tkzPointResult)
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
% \def\tkz@recuplast(#1,#2){\def\tkz@last{#1}}
% \def\tkz@stop{\tkz@stop}
%<--------------------------------------------------------------------------–>
%                                    medians
%<--------------------------------------------------------------------------–>
\def\tkz@@Medians(#1,#2,#3)(#4,#5){%
    \def\tkz@tmp{#5}%
   \ifx\tkz@tmp\tkz@stop\else\tkz@@Medians(#2,#3)(#5)\fi
   \tkz@recuplast(#3)

    \pgfcoordinate{#4}{\pgfpointscale{0.5}{%
          \pgfpointadd{\pgfpointanchor{#2}{center}}{%
                       \pgfpointanchor{\tkz@last}{center}}%
      }}%
    \protected@edef\tkz@temp{\noexpand
         \tkzDrawLine[add= 0 and 0,/DrawTLines/.cd,\tkz@opttline](#4,#1)}\tkz@temp%
   \ifx\tkzutil@empty\tkz@newpoint@name
     \else
        \coordinate (\tkz@newpoint@name#4) at (#4);
     \fi
}
\def\tkzDrawMedians{\pgfutil@ifnextchar[{\tkz@Medians}{\tkz@Medians[]}}
\def\tkz@Medians[#1](#2)#3{%
\begingroup
   \xdef\tkz@opttline{#1}
   \tkz@@Medians(#2,#2)(#3,\tkz@stop)
   \endgroup
}

%<--------------------------------------------------------------------------–>
%                    Altitudes
%<--------------------------------------------------------------------------–>
\def\tkz@@Altitudes(#1,#2,#3)(#4,#5){%
  \def\tkz@tmp{#5}%
   \ifx\tkz@tmp\tkz@stop\else\tkz@@Altitudes(#2,#3)(#5)\fi
      \tkz@recuplast(#3)
      \tkzUProjection(#2,\tkz@last)(#1)
      \pgfnodealias{tkz@tmp@pt}{tkzPointResult}
 \protected@edef\tkz@temp{%
   \noexpand
   \tkzDrawLine[add= 0 and 0,/DrawTLines/.cd,\tkz@opttline](#1,tkz@tmp@pt)}\tkz@temp%
     \ifx\tkzutil@empty\tkz@newpoint@name
     \else
        \coordinate (\tkz@newpoint@name#4) at (tkz@tmp@pt);
     \fi
}
\def\tkzDrawAltitudes{\pgfutil@ifnextchar[{\tkz@DrawAltitudes}{\tkz@DrawAltitudes[]}}
\def\tkz@DrawAltitudes[#1](#2)#3{%
\begingroup
   \xdef\tkz@opttline{#1}
   \tkz@@Altitudes(#2,#2)(#3,\tkz@stop)
   \endgroup
   }
%<--------------------------------------------------------------------------–>
%                    bisectors
%<--------------------------------------------------------------------------–>
\def\tkz@@Bisectors(#1,#2,#3)(#4,#5){%
\def\tkz@tmp{#5}%
\ifx\tkz@tmp\tkz@stop\else\tkz@@Bisectors(#2,#3)(#5)\fi
  \tkz@recuplast(#3)
  \tkzDefBisectorLine(\tkz@last,#1,#2)
  \tkzInterLL(#2,\tkz@last)(#1,tkzPointResult)
  \pgfnodealias{tkz@tmp@pt}{tkzPointResult}
  \protected@edef\tkz@temp{
    \noexpand \tkzDrawLine[add= 0 and 0,
                           /DrawTLines/.cd,
                          \tkz@opttline](#1,tkz@tmp@pt)}\tkz@temp
  \ifx\tkzutil@empty\tkz@newpoint@name
    \else
      \coordinate (\tkz@newpoint@name#4) at (tkz@tmp@pt);
  \fi
}
\def\tkzDrawBisectors{\pgfutil@ifnextchar[{\tkz@DrawBisectors}{\tkz@DrawBisectors[]}}

\def\tkz@DrawBisectors[#1](#2)#3{%
\begingroup
   \xdef\tkz@opttline{#1}
   \tkz@@Bisectors(#2,#2)(#3,\tkz@stop)
\endgroup
}
%<-------------------------------------------------------------------------–
%<-------------------------------------------------------------------------–
%<-------------------------------------------------------------------------–
\def\tkz@numdtls{0}
\pgfkeys{/DrawTLines/.cd,
      median/.code                  =   \def\tkz@numdtls{0},
      altitude/.code                =   \def\tkz@numdtls{1},
      bisector/.code                =   \def\tkz@numdtls{2},
      median,
      name/.store in                =   \tkz@newpoint@name,
      name/.initial                 = {},
      name                          = {},
   /DrawTLines/.search also={/tikz}
}
%<--------------------------------------------------------------------------–>
%            Drawing tr lines                                                >
%<--------------------------------------------------------------------------–>
\def\tkzDrawTLines{\pgfutil@ifnextchar[{\tkz@DrawTLines}{\tkz@DrawTLines[]}}
\def\tkz@DrawTLines[#1](#2)#3{%
\begingroup
\pgfqkeys{/DrawTLines}{#1}
\ifcase\tkz@numdtls%
    \tkzDrawMedians[#1](#2){#3}
  \or% 1
    \tkzDrawAltitudes[#1](#2){#3}
  \or% 2
    \tkzDrawBisectors[#1](#2){#3}
 \fi
\endgroup
}
%<-------------------------------------------------------------------------–
%         tkzDrawLines
%<-------------------------------------------------------------------------–
\def\tkz@@multiLines#1 #2\@nil{%
  \protected@edef\tkz@temp{
    \noexpand \tkzDrawLine[\tkz@optline](#1)}\tkz@temp%
   \def\tkz@nextArg{#2}%
   \ifx\tkzutil@empty\tkz@nextArg
     \let\next\@gobble
   \fi
   \next#2\@nil
}
%<--------------------------------------------------------------------------–>
\def\tkzDrawLines{\pgfutil@ifnextchar[{\tkz@DrawLines}{%
           \tkz@DrawLines[]}}
\def\tkz@DrawLines[#1](#2){%
\xdef\tkz@optline{#1}
\begingroup
   \let\next\tkz@@multiLines
   \next#2 \@nil %
\endgroup
}%
%<-------------------------------------------------------------------------–>
%   Label
%<-------------------------------------------------------------------------–>
\def\tkzLabelLine{\pgfutil@ifnextchar[{\tkz@AddLabelLine}{\tkz@AddLabelLine[]}}
\def\tkz@AddLabelLine[#1](#2,#3)#4{\path  (#2) to node[#1]{#4}(#3);}

%<--------------------------------------------------------------------------–>
%                                Setup   Line
%<--------------------------------------------------------------------------–>
\pgfkeys{%
   tkzsuline/.cd,
   line width/.code =   {\xdef\tkz@line@lw{#1}},
   color/.code      =   {\xdef\tkz@line@color{#1}},
   style/.code      =   {\xdef\tkz@line@style{#1}},
   add/.code args   =   {#1 and #2} {\xdef\tkz@line@left{#1}%
                                    \xdef\tkz@line@right{#2}},
       /tkzsuline/.search also={/tikz}%
}
%<--------------------------------------------------------------------------–>
\def\tkzSetUpLine{\pgfutil@ifnextchar[{\tkz@SetUpLine}{% remove tkzActivOff 3.03
                                      \tkz@SetUpLine[]}}
\def\tkz@SetUpLine[#1]{%
\pgfkeys{%
      tkzsuline/.cd,
      line width   = \tkz@euc@linewidth,
      color        = \tkz@euc@linecolor,
      style        = \tkz@euc@linestyle,
      add          = {\tkz@euc@lineleft} and {\tkz@euc@lineright}}
\pgfqkeys{/tkzsuline}{#1}
%<--------------------------------------------------------------------------–>
%                              Line style
%<--------------------------------------------------------------------------–>
\tikzset{%
        line style/.style ={%
        color             = \tkz@line@color,
        line width        = \tkz@line@lw,
        style             = \tkz@line@style,
        add               = {\tkz@line@left} and {\tkz@line@right}
}}}% end setup
%<--------------------------------------------------------------------------–>
%                             draw      segment  (s)
%<--------------------------------------------------------------------------–>
\pgfkeys{/tkzdraws/.cd,
  /tkzdraws/.search also={/tikz},
}
\def\tkzDrawSegment{\pgfutil@ifnextchar[{\tkz@DrawSegment}{%
                                         \tkz@DrawSegment[]}}
\def\tkz@DrawSegment[#1](#2,#3){%
\begingroup
  \pgfqkeys{/tkzdraws}{#1}
  \draw[line style,add=0 and 0,#1] (#2) to (#3);
\endgroup
}%

\def\tkz@multiDrawSeg#1 #2\@nil{%
 \protected@edef\tkz@temp{
   \noexpand \tkzDrawSegment[\tkz@optseg](#1)}\tkz@temp%
   \def\tkz@nextArg{#2}%
   \ifx\tkzutil@empty\tkz@nextArg
     \let\next\@gobble
   \fi
   \next#2\@nil
}
\def\tkzDrawSegments{\pgfutil@ifnextchar[{\tkz@DrawSegments}{%
                                         \tkz@DrawSegments[]}}
\def\tkz@DrawSegments[#1](#2){%
\def\tkz@optseg{#1}
\begingroup
  \let\next\tkz@multiDrawSeg
  \next#2 \@nil %
\endgroup
}
%<--------------------------------------------------------------------------–>
%                               Mark   Segment
%<--------------------------------------------------------------------------–>
\pgfkeys{
  /@tkzmarkoptions/.cd,
     pos/.store in       = \tkz@mkpos,
     color/.store in     = \tkz@mkcolor,
     mark/.store in      = \tkz@markseg,
     size/.store in      = \tkz@mksize,
     size                = 4pt,
     color               = \tkz@mk@color,
     pos                 = .5,
     mark                = |,
    /@tkzmarkoptions/.search also={/tikz},
}
\def\tkzMarkSegment{\pgfutil@ifnextchar[{\tkz@MarkSegment}{\tkz@MarkSegment[]}}
\def\tkz@MarkSegment[#1](#2,#3){%
\begingroup
 \pgfqkeys{/@tkzmarkoptions}{#1}
\def\tkz@mymark{\pgfsetplotmarksize{\tkz@mksize}\pgfuseplotmark{\tkz@markseg}}
\begin{scope}
  [decoration={markings,mark=at position \tkz@mkpos with {\tkz@mymark}}]
  \path [\tkz@mkcolor,/@tkzmarkoptions/.cd,#1,postaction={decorate}] (#2) -- (#3);
\end{scope}
\endgroup
}
%<--------------------------------------------------------------------------–>
% multiple
\def\tkz@multiMS#1 #2\@nil{%
 \protected@edef\tkz@temp{
   \noexpand \tkzMarkSegment[\tkz@optsg](#1)}\tkz@temp%
   \def\tkz@nextArg{#2}%
   \ifx\tkzutil@empty\tkz@nextArg
     \let\next\@gobble
   \fi
   \next#2\@nil
}
%<--------------------------------------------------------------------------–>
\def\tkzMarkSegments{\pgfutil@ifnextchar[{\tkz@MarkSegments}{\tkz@MarkSegments[]}}
\def\tkz@MarkSegments[#1](#2){%
\def\tkz@optsg{#1}
  \begingroup
   \let\next\tkz@multiMS
   \next#2 \@nil %
\endgroup
}
%<-------------------------------------------------------------------------–>
%             Label on segment
%<-------------------------------------------------------------------------–>
\def\tkzLabelSegment{\pgfutil@ifnextchar[{\tkz@LabelSegment}%
                     {\tkz@LabelSegment[]}}
\def\tkz@LabelSegment[#1](#2,#3)#4{%
\begingroup
  \path  (#2) to node[label seg style,#1]{#4} (#3) ;
\endgroup
}
%<--------------------------------------------------------------------------–>
% multiple
\def\tkz@multiLS#1 #2\@nil{%
 \protected@edef\tkz@temp{
   \noexpand \tkzLabelSegment[\tkz@optls](#1){\tkz@labelseg}}\tkz@temp%
   \def\tkz@nextArg{#2}%
   \ifx\tkzutil@empty\tkz@nextArg
     \let\next\@gobble
   \fi
   \next#2\@nil
}
%<--------------------------------------------------------------------------–>
\def\tkzLabelSegments{\pgfutil@ifnextchar[{\tkz@LabelSegments}{\tkz@LabelSegments[]}}
\def\tkz@LabelSegments[#1](#2)#3{%
\def\tkz@optls{#1}
\def\tkz@labelseg{#3}
  \begingroup
   \let\next\tkz@multiLS
   \next#2 \@nil %
\endgroup
}
%<--------------------------------------------------------------------------–>
%             PolySeg
%<--------------------------------------------------------------------------–>
\def\tkzDrawPolySeg{\pgfutil@ifnextchar[{\tkz@DrawPolySeg}{\tkz@DrawPolySeg[]}}
\def\tkz@DrawPolySeg[#1](#2,#3){%
\begingroup
\draw[line style,#1] (#2)
     \foreach \pt in {#2,#3}{--(\pt)};%
\endgroup
}


%<--------------------------------------------------------------------------–>
%  add dim
    % \draw[dim={5cm,7pt,}]   (A) --  (B);
    % \draw[dim={7cm,10pt,transform shape}]  (B) --  (C);
    % \draw[dim={X,,}]  (A) --  (C);
%<--------------------------------------------------------------------------–>
\pgfkeys{/pgf/decoration/.cd, distance/.initial = 10pt}

\pgfdeclaredecoration{add dim}{final}{
\state{final}{%
\pgfmathsetmacro{\dist}{\pgfkeysvalueof{/pgf/decoration/distance}}
          \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
          \pgfpathlineto{\pgfpoint{0pt}{1.2*\dist}}
          \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
          \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{1.2*\dist}}
          \pgfsetarrowsstart{latex}
          \pgfsetarrowsend{latex}
          \pgfpathmoveto{\pgfpoint{0pt}{\dist}}
          \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}}
          \pgfusepath{stroke}
          \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
          \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
}}

\tikzset{
    dim/.style args={#1,#2,#3}{%
                decoration = {add dim,distance=\ifx&#2&0pt\else#2\fi},
                decorate,
                postaction = {%
                   decorate,
                   decoration={%
                        raise=#2,
                        markings,
                        mark=at position .5 with {%
            \node[inner sep=0pt,
                              font=\footnotesize,
                              fill=\tkz@fillcolor,
                              #3] at (0,0) {#1};}
                   }
                }
    },
    dim/.default={,0pt,}
}

%<---------------------------  style line --------------------------------->
\tikzset{add/.style args={#1 and #2}{to path={%
 ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
  \tikztonodes}}
}
%<--------------------------------------------------------------------------–>
\makeatother
\endinput
